/**
 * 下载后端返回的文件流
 * @param fileStream 文件流
 * @param fileName 保存文件名称
 */
export default (fileStream, fileName = '默认', key) => {
  /* 兼容ie内核，360浏览器的兼容模式 */
  if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    let blob = new Blob([fileStream], {
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    })
    window.navigator.msSaveOrOpenBlob(blob, `${fileName}.xlsx`)
  } else {
    let blob = new Blob([fileStream], {
      // 这里可能会又变化
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheetcharset=utf-8'
    })
    let downloadElement = document.createElement('a')
    let href = window.URL.createObjectURL(blob)
    downloadElement.href = href
    downloadElement.download = `${fileName}.${key}`
    document.body.appendChild(downloadElement)
    downloadElement.click()
    document.body.removeChild(downloadElement)
    window.URL.revokeObjectURL(href)
  }
}
